package com.gitee.Transformation

import org.apache.flink.api.scala.ExecutionEnvironment

/*
  聚合操作,要先分组再聚合,和sum操作有点相似
 */
object ReduceTest {
  def main(args: Array[String]): Unit = {
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    import org.apache.flink.api.scala._
    env.setParallelism(1)
    case class User(id: String, name: String)
    val lineData: DataSet[(String, Int)] = env.fromElements(("java",1),("jva",1),("java",1))

    lineData.groupBy(0).reduce((t1,t2)=>(t1._1,t1._2+t2._2)).print()

    lineData.groupBy(0).sum(1).print()

  }
}
